<?php
class Training_FilterController extends Zend_Controller_Action{

	public function init() {
            parent::init();
			$this->_helper->viewRenderer->setNoRender();
			$this->_helper->layout->disableLayout();
	}
	
	public function multiAction() {
		$str = "http:www.zend.vn/Khóa học zend Framework cung @#$%^*&!@#()_-+
														cấp những     kiến    thức cơ    bản về zend framework";
		$newArr = explode('vn/', $str);
		
		echo '<br>' . $str_1 = $newArr[0] . 'vn/';
		echo '<br>' . $str_2 = $newArr[1];
		
		$filter = new Zend_Filter();
		$multiFilter = $filter->addFilter(new Zend_Filter_StringToLower(), array('encoding'=>'UTF-8'))
							  ->addFilter(new Zend_Filter_Alnum(true))
							  ->addFilter(new Zend_Filter_PregReplace(array('match'=>'#\s+#', 'replace'=>'-')))
							  ->addFilter(new Zend_Filter_Word_SeparatorToDash())
							  ->addFilter(new Zendvn_Filter_RemoveCircumflex());
		
		$result = $multiFilter->filter($str_2);
		$result = $str_1 . $result . '.html';
		echo '<br>Source: ' . $result;
	}
	
	
	public function removeAction() {
		$str = "a à ả ã á ạ ă ằ ẳ ẵ ắ ặ â ầ ẩ ẫ ấ ậ b c d đ e è ẻ ẽ é ẹ ê ề ể ễ ế ệ <br/>
				f g h i ì ỉ ĩ í ị j k l m n o ò ỏ õ ó ọ ô ồ ổ ỗ ố ộ ơ ờ ở ỡ ớ ợ  <br/>
				p q r s t u ù ủ ũ ú ụ ư ừ ử ữ ứ ự v w x y ỳ ỷ ỹ ý ỵ z";
		$filter = new Zendvn_Filter_RemoveCircumflex();
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function linkAction() {
		$str = "   Các kiến   thức cơ  bản về filter    trong Zend Framework       ";
		$findwork = 'Zend Framework';
		$link = 'trieuhieu509a@gmail.com';
		$filter = new Zendvn_Filter_AddLink($findwork, $link);
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function pregAction() {
		$str = "   Các kiến   thức cơ  bản về filter    trong Zend Framework       ";
		$filter = new Zend_Filter_PregReplace(array('match'=>'#\s+#', 'replace'=>'-'));
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	

	public function separator2Action() {
		$str = "     Các kiến thức cơ bản về filter trong Zend Framework       ";
		$filter = new Zend_Filter_Word_SeparatorToSeparator(' ', '+');
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
		
	//Chuyển khoảng trắng thành gạch giữa
	public function separatorAction() {
		$str = "     Các kiến thức cơ bản về    filter trong Zend Framework       ";
		$filter = new Zend_Filter_Word_SeparatorToDash();
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	//Giải nén thư mục
	public function unzipAction() {
		$option = array(
			'adapter' => 'zip',
			'options' => array(
				'target'=> TEMP_PATH . '/unzip'
			),
		);
		$filter = new Zend_Filter_Decompress($option);
		$result = $filter->filter(TEMP_PATH . '/demo.zip');
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	//Nén thư mục
	public function zip3Action() {
		$option = array(
			'adapter' => 'zip',
			'options' => array(
				'archive'=> TEMP_PATH . '/folder.zip'
			),
		);
		$filter = new Zend_Filter_Compress($option);
		$result = $filter->filter(TEMP_PATH . '/images');
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	//Nen file
	public function zipAction() {
		$option = array(
			'adapter' => 'zip',
			'options' => array(
				'archive'=> TEMP_PATH . '/demo.zip'
			),
		);
		$filter = new Zend_Filter_Compress($option);
		$result = $filter->filter(TEMP_PATH . '/compressme.txt');
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	//Loại bỏ thẻ html
	public function tagAction() {
//		$str = "<b>My content </b>";
		$str = "This contains <a href='http://example.com'>no ending task </a>";
		$filter = new Zend_Filter_StripTags();
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function trimAction() {
		$str = "     Các kiến thức cơ bản về filter trong Zend Framework       ";
		$filter = new Zend_Filter_StringTrim(array('encoding'=>'UTF-8'));
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function upperAction() {
		
		$str = "Các kiến thức cơ bản về filter trong Zend Framework";
		$filter = new Zend_Filter_StringToUpper(array('encoding'=>'UTF-8'));
//		$filter->setEncoding('UTF-8');
//		strrev($str);
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function lowerAction() {
		
		$str = "Các kiến thức cơ bản về filter trong Zend Framework";
		$filter = new Zend_Filter_StringToLower(array('encoding'=>'UTF-8'));
//		$filter->setEncoding('UTF-8');
//		strrev($str);
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function digitAction() {
		
		$str = "0123.ắ ớ123 áđâsd";
		$filter = new Zend_Filter_Digits();
//		strrev($str);
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function strrevAction() {
		
		$str = "i love you so much";
		$filter = new Zend_Filter_Callback('strrev');
//		strrev($str);
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function dirAction() {
		
		$str = "http://framework.zend.com/manual/1.12/en/zend.filter.set.html";
		$filter = new Zend_Filter_Dir();
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	public function fileAction() {
		
		$str = "http://framework.zend.com/manual/1.12/en/zend.filter.set.html";
		$filter = new Zend_Filter_BaseName();
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	//Chi lay ki tu
	public function alphaAction() {
		
		$str = "a s d! @##%^*&()  *()(*!@~@~~@ 123a sf bcvb |<>?'";
		$filter = new Zend_Filter_Alpha(true);
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
	
	/* Chi lay so, ki tu
	 * Tham so true : lay khoang trang
	 */
	public function alnumAction() {
		
		$str = "asd!@##%^*&()  *()(*!@~@~~@ 123asfbcvb |<>?'";
		$filter = new Zend_Filter_Alnum(true);
		
		$result = $filter->filter($str);
		
		echo '<br>Source: ' . $str;
		echo '<br>Source: ' . $result;
	}
}